import { injectable } from 'inversify';
import Cookies from 'js-cookie';

@injectable()
export class CookieRepository {
  constructor(private cookie = Cookies) {}

  get(key: string) {
    return this.cookie.get(key);
  }

  set(key: string, value: string, expires?: number) {
    return this.cookie.set(key, value, {
      secure: true,
      expires: expires ? expires / 60 / 60 / 24 : undefined,
      path: '/',
    });
  }

  delete(key: string) {
    return this.cookie.remove(key, { secure: true });
  }
}
